package com.stt.order.base.service;

import com.stt.order.model.Order;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;

@Service
public class DiscountService {

    /**
     * 计算订单折扣和优惠
     * @param order
     */
    public void calculateDiscount(Order order) {
        BigDecimal finalAmount = order.getOriginalAmount();
        
        // 根据用户类型计算折扣
        switch (order.getUserType()) {
            case "VIP":
                finalAmount = finalAmount.multiply(new BigDecimal("0.8")); // VIP享8折
                break;
            case "ENTERPRISE":
                finalAmount = finalAmount.multiply(new BigDecimal("0.7")); // 企业用户享7折
                break;
            default:
                // 普通用户无折扣
                break;
        }
        
        // 根据促销类型计算优惠
        switch (order.getPromotionType()) {
            case "FULL_REDUCTION":
                // 满1000减100
                if (finalAmount.compareTo(new BigDecimal("1000")) >= 0) {
                    finalAmount = finalAmount.subtract(new BigDecimal("100"));
                }
                break;
            case "DISCOUNT":
                // 额外95折
                finalAmount = finalAmount.multiply(new BigDecimal("0.95"));
                break;
            case "GIFT":
                // 赠品促销不影响订单金额
                break;
        }
        
        order.setFinalAmount(finalAmount);
    }
} 